import Vue from 'vue'
export function request(url, data, method) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: Vue.prototype.$URL + url,
			data,
			method,
			header: {
				"Content-Type": "application/json",
				'Accept': 'application/json',
				// 'token': "eyJhbGciOiJIUzI1NiJ9.eyJhY2NvdW50IjoiMjk0MzQwNTEwNiIsImlhdCI6MTc1MDE1MjUzNCwiZXhwIjoxNzgxNjg4NTM0fQ.Mh9IfHVUPRph7hBYaZSfdZzExu3qPuUOkp6KAwwCXCk"
				'token': uni.getStorageSync('token')
			},
			success: res => {
				// 如果为未登录则跳转到登录页面
				if (res.data.code == 90002) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}
				// 如果token不合法同样跳转
				else if (res.data.code == 10003) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}
				// 或者用户不存在
				else if (res.data.code == 10059) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}
				// 否则正常返回
				else {
					resolve(res)
				}
			},
			fail: err => {
				reject(err)
			}
		})
	})
}